#include "keyboard.h"

KeyBoard::KeyBoard(QWidget *parent) : QWidget(parent)
{
    model = new ListModel;

    delegate = new Delegate;
    connect(delegate, &Delegate::itemClicked, this, &KeyBoard::itemClick);

    listview = new ListView(this);
    listview->setViewMode(QListView::IconMode);
    listview->setFlow(QListView::LeftToRight);
    listview->setMovement(QListView::Static);
    listview->setGridSize(QSize(86, 86));
    listview->setModel(model);
    listview->setFixedSize(780, 200);
    listview->setItemDelegate(delegate);
    qDebug() << width() << " " << height();
}

void KeyBoard::init_small()
{
    const KeyInfo list[] = {
        {"a", ""},{"b", ""},{"c", ""},{"d", ""},
        {"e", ""},{"f", ""},{"g", ""},{"h", ""},
        {"i", ""},{"j", ""},{"k", ""},{"l", ""},
        {"m", ""},{"n", ""},{"o", ""},{"p", ""},
        {"q", ""},{"r", ""},{"s", ""},{"t", ""},
        {"u", ""},{"v", ""},{"w", ""},{"x", ""},
        {"y", ""},{"z", ""},
        {"A/a", ""},
        {"123", ""},
        {"->", ""}
    };

    model->clear();
    for(int i=0; i<29; i++)
    {
        model->addData(list[i].data, list[i].icon);
    }
}

void KeyBoard::init_larget()
{
    const KeyInfo list[] = {
        {"A", ""},{"B", ""},{"C", ""},{"D", ""},
        {"E", ""},{"F", ""},{"G", ""},{"H", ""},
        {"I", ""},{"J", ""},{"K", ""},{"L", ""},
        {"M", ""},{"N", ""},{"O", ""},{"P", ""},
        {"Q", ""},{"R", ""},{"S", ""},{"T", ""},
        {"U", ""},{"V", ""},{"W", ""},{"X", ""},
        {"Y", ""},{"Z", ""},
        {"a/A", ""},
        {"123", ""},
        {"->", ""}
    };

    model->clear();
    for(int i=0; i<29; i++)
    {
        model->addData(list[i].data, list[i].icon);
    }
}

void KeyBoard::init_number()
{
    const KeyInfo list[] = {
        {"1", ""},{"2", ""},{"3", ""},{"4", ""},
        {"5", ""},{"6", ""},{"7", ""},{"8", ""},
        {"9", ""},{"0", ""},
        {"a/A", ""},
        {"->", ""}
    };

    model->clear();
    for(int i=0; i<12; i++)
    {
        model->addData(list[i].data, list[i].icon);
    }
}

